package org.example;

import java.util.HashMap;

public class MyClassLoader extends ClassLoader {

    HashMap<String, byte[]> map;

    public MyClassLoader(HashMap<String, byte[]> map) {
        super();
        this.map = map;
    }

    @Override
    public Class<?> findClass(String classFile) throws ClassNotFoundException {
        // classFile为class文件的路径名,如 F:/lib/org/example/App.class
        if (classFile != null) {
            System.out.println("自定义类加载器正在加载类: " + classFile);
            byte[] bytes = map.get(classFile);
            return defineClass(null, bytes, 0, bytes.length);
        }
        return null;
    }
}